<?php

/**
 * Description of Sxd
 *
 * @author xtceetg
 */
class Sxd {

    const KEY = '413f2b4638613c9208ef881a30ec2ca7';

    /**
     * 获取游戏登录地址
     * @param type $userinfo 用户信息
     * @param type $serverinfo 服务器信息
     * @param int $pc 登录方式 0为web 1为微端
     * @return array
     */
    public static function enter_game($userinfo, $serverinfo, $pc = 0) {
        //var_dump($userinfo,$serverinfo);exit;
        $uid = $userinfo['uid'];
        $gid = $serverinfo['ishf'] == 1 ? $serverinfo['hf_gid'] : $serverinfo['game_id'];
        $sid = $serverinfo['ishf'] == 1 ? $serverinfo['hf_sid'] : $serverinfo['server_key'];
        $dateline = time();
        $mid = 2;
        $pc = 0;
        $fcm = 0;
        $sign = md5($uid . $gid . $sid . $mid . $dateline . self::KEY);
        $url = file_get_contents($serverinfo['domain'] ."/?tp=login". "&uid=" . $uid . "&gid=" . $gid . "&sid=" . $sid . "&mid=" . $mid . "&dateline=" . $dateline . "&pc=" . $pc . "&fcm=" . $fcm . "&sign=" . $sign);
        
        return array(
            'url' => $url,
            'msg' => 0, //0表示网站登录
            'pc' => $pc
        );
    }

    public static function pay_to_game($serverinfo, $orderinfo) {
        $oid = $orderinfo['order_num'];
        $uid = $orderinfo['pay_uid'];
        $gid = $serverinfo['ishf'] == 1 ? $serverinfo['hf_gid'] : $serverinfo['game_id'];
        $sid = $serverinfo['ishf'] == 1 ? $serverinfo['hf_sid'] : $serverinfo['server_key'];
        $money = intval($orderinfo['fee_cny']);
        $mid = 2;
        //file_put_contents('/home/wwwroot/www.248game.com/Application/Runtime/Logs/pay/pay.txt', var_export($orderinfo, TRUE), FILE_APPEND | LOCK_EX);
        $sign = md5($oid . $uid . $gid . $sid . $mid . $money . self::KEY);
        $url = "http://yylm.265g.com/?tp=pay&uid={$uid}&gid={$gid}&sid={$sid}&mid={$mid}&oid={$oid}&money={$money}&sign={$sign}";

        //file_put_contents('/home/wwwroot/www.248game.com/Application/Runtime/Logs/pay/pay.txt', $url, FILE_APPEND | LOCK_EX);
        $result = file_get_contents($url);
        file_put_contents('/home/wwwroot/www.248game.com/Application/Runtime/Logs/pay/' . $oid . '.txt', $result);
        return $result == 0 ? 0 : 1;
    }
    
    public static function get_libao($userinfo,$serverinfo,$type="xslb"){             
        $uid=$userinfo['uid'];
        $gid=$serverinfo['ishf'] == 1 ? 1 : $serverinfo['game_id'];
        $sid=$serverinfo['ishf'] == 1 ? $serverinfo['hf_sid'] : $serverinfo['server_key'];
        $mid=2;
        $type='xslb';
        $p=true;
        $cate=1;
        $url="http://wan.265g.com/index.php?tp=card&gid={$gid}&sid={$sid}&uid={$uid}&type=xslb&cate={$cate}&mid={$mid}";        
        $cardNo=  file_get_contents($url);
        if($cardNo){
            return array('ret'=>0,'card'=>$cardNo);
        }else{
            return array('ret'=>1,'card'=>'卡号获取错误，请稍后在试');
        }
    }

}
